<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
global $language;
$language = 'en';
header( 'Content-type: text/html; charset=utf-8' );
include_once( "global/old_database_connection.php" );
include( "global/translations.php" );
include( "global/utils.php" );
$query5 = "SELECT language, title " .
		"FROM languages " .
		"ORDER BY title";
$result5 = mysql_query( $query5 ) or die( "Query failed : " . mysql_error() );
$num5 = mysql_numrows( $result5 );
if( isset( $_GET[ 'language' ] ) ) {
	$i = 0;
	while ( $i < $num5 ) {
		if( $_GET[ 'language' ] == mysql_result( $result5, $i, 'language' ) ) {
			$language = mysql_result( $result5, $i, 'language' );
			break;
		}
		$i ++;
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>Ages of Strife: <?php transprint( 'Rounds' ); ?></title>
		<link type="text/css" rel="stylesheet" href="global/agesofstrife.css"></link>
	</head>
	<body>
		<div id="root_container">
			<div align="center" id="header-image">
				<a href="index.php?language=<?php print( $language ); ?>">
					<img class="header-dummy-image" src="resources/dummy.gif" alt="Ages of Strife" border="0" />
				</a>
			</div>
<?php
include( "global/ads.php" );
?>
			<div id="container">
				<div id="main-content">
					<h2>
						Ages of Strife <?php transprint( 'rounds' ); ?>
					</h2>
					<div class="blok">
						<?php transprint( 'Click' ); ?> <a href="index.php?language=<?php print( $language ); ?>"><?php transprint( 'here' ); ?></a> <?php transprint( 'to go back to the main page.' ); ?><br />
						<br />
						<small>(<?php transprint( 'Click on a round name to see the rounds hall of fame' ); ?>)</small><br />
<?php
include_once( "global/old_database_connection.php" );
$query = "SELECT * FROM round WHERE round.show = 1 ORDER BY round_id";
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$num = mysql_numrows( $result );
$i = 0;
if( $num > 0 ) {
	?>
				</div>
				<br />
				<table id="twothird">
					<tr><th colspan="5">
						<?php transprint( 'Rounds' ); ?>
					</th></tr>
					<tr>
						<td><?php transprint( 'Name' ); ?></td>
						<td><?php transprint( 'Turns' ); ?></td>
						<td><?php transprint( 'Rulers' ); ?></td>
						<td><?php transprint( 'Villages' ); ?></td>
						<td><?php transprint( 'World population' ); ?></td>
					</tr>
	<?php 
	while( $i < $num ) {
		if( $i % 2 == 0 ) {
	        print "<tr id=\"even\">";
	    }
	    else {
	        print "<tr>";
	    }
	    print( "<td><a href=\"hall_of_fame.php?round=" . urlencode( mysql_result( $result, $i, "name" ) ) . "&language=$language\" title=\"Hall of Fame\">" . mysql_result( $result, $i, "name" ) . "</a></td>" );
	    print( "<td>" . number_format( mysql_result( $result, $i, "turns" ) ) . "</td>" );
	    print( "<td>" . number_format( mysql_result( $result, $i, "rulers" ) ) . "</td>" );
	    print( "<td>" . number_format( mysql_result( $result, $i, "villages" ) ) . "</td>" );
	    print( "<td>" . number_format( mysql_result( $result, $i, "population" ) ) . "</td>" );
	    print( "</tr>\r\n" );			
		$i ++;
	}
	?>
				</table>
	<?php
}
else {
	print( translate( "No recorded rounds yet." ) . "</div>" );
}
?>
					<br />
					<div class="blok">
						<strong><?php transprint( 'Most decorated players of all rounds' ); ?></strong><br />
						<ol>
<?php
$query = "SELECT DISTINCT username, users.user_id " .
		"FROM users " .
		"JOIN medals ON users.user_id = medals.user_id " .
		"WHERE username != 'Zworf' " .
		"ORDER BY ( SELECT SUM( value ) FROM medals AS medals2 WHERE medals2.user_id = users.user_id ) DESC " .
		"LIMIT 25";
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$num = mysql_numrows( $result );
$i = 0;
while( $num > $i ) {
?>
							<li>
								<?php print( mysql_result( $result, $i, "username" ) ); ?><br />
<?php 
	printMedals( mysql_result( $result, $i, 'user_id' ) );
?>
							</li>

<?php
	$i ++;
}

?>
						</ol>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="global/merge_javascript.php?version=<?php require('global/merge_javascript.php'); ?>"></script>
	</body>
</html>